package me.zhengjie.modules.quartz.utils;

import lombok.extern.slf4j.Slf4j;

/**
 * @Author: youqing.yang
 * @Create: 2021/06/22 18:37
 * @Description:
 **/
@Slf4j
public class WXPublicUtils {
    /**
     * 验证Token
     * @param msgSignature 签名串，对应URL参数的signature
     * @param timeStamp 时间戳，对应URL参数的timestamp
     * @param nonce 随机串，对应URL参数的nonce
     *
     * @return 是否为安全签名
     * @throws AesException 执行失败，请查看该异常的错误码和具体的错误信息
     */
    public static boolean verifyUrl(String msgSignature, String timeStamp, String nonce)
            throws AesException {
        log.info("verifyUrl params msgSignature:{},timeStamp:{},nonce:{}", msgSignature, timeStamp, nonce);
        //填写自己设置的Token
        String signature = SHA1.getSHA1("testToken_verifyUrl_688", timeStamp, nonce);
        log.info("signature:{}", signature);
        if (!signature.equals(msgSignature)) {
            throw new AesException(AesException.ValidateSignatureError);
        }
        return true;
    }
}
